package com.qingzhuge.manager.entity;


import com.qingzhuge.common.enums.ERoleType;
import com.qingzhuge.entity.BaseModel;
import com.qingzhuge.resource.entity.SysResource;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;

/**
 * @author : zero.xiao
 * @description : 角色
 * @date :2018/6/8 0008 下午 15:01
 * @modified :
 * @since : 1.0.0
 */
@EqualsAndHashCode(callSuper = true)
@Data
@Entity
@Table(name = "sys_role")
public class SysRole extends BaseModel {
    private static final long serialVersionUID = -7523552506077974207L;
    /**
     * 用户类型(1普通用户2管理员3系统用户)
     */
    private ERoleType type;

    private Boolean root;
    /**
     * 部门ID
     */
    private Long deptId;
    @ManyToMany(fetch = FetchType.EAGER)
    @JoinTable(name = "sys_role_resource",
            joinColumns = {@JoinColumn(name = "role_id")},
            inverseJoinColumns = {@JoinColumn(name = "resource_id")})
    private List<SysResource> resources = new ArrayList<>();

    @Transient
    private String permission;

    public SysRole() {
    }

    public SysRole(String name) {
        super(name);
    }

    public SysRole(Long id) {
        super(id);
    }

    public SysRole(String name, Long id) {
        super(name, id);
    }
}
